package com.heima.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {

    // 交换机
    public static final String SECKILL_EXCHANGE = "seckill.exchange";
    // 队列
    public static final String SECKILL_QUEUE = "seckill.queue";
    // 路由键
    public static final String SECKILL_ROUTE_KEY = "seckill.route";

    @Bean
    public Exchange seckillExchange() {
        return ExchangeBuilder.directExchange(SECKILL_EXCHANGE)
                .durable(true)
                .build();
    }

    @Bean
    public Queue seckillQueue() {
        return QueueBuilder.durable(SECKILL_QUEUE)
                .build();
    }

    @Bean
    public Binding seckillBinding() {
        return BindingBuilder.bind(seckillQueue())
                .to(seckillExchange())
                .with(SECKILL_ROUTE_KEY)
                .noargs();
    }
}